package thread.synchronize.dirtyread;

/**
 * 脏读
 *
 * @author cuihao
 * @date 2018/3/2
 */
public class PublicVar {
    public String username = "A";
    public String password = "AA";

    synchronized public void setValue(String username, String password) {
        try {
            this.username = username;
            Thread.sleep(3000);
            this.password = password;
            System.out.println("current thread = " + Thread.currentThread().getName() + " username = " + username
                + " password = " + password);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void getValue() {
        System.out.println("username = " + username + " password = " + password);
    }
}
